/**
 * 
 */
package pl.prv.polanie.client.widgets;

import pl.prv.polanie.client.widgets.CustomDialogBox;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PopupListener;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author Janusz
 *
 */
public class AcademicTitleForm extends CustomDialogBox {
	
	private final String styleButton = "customButton_1";
	
	private final String styleDescribeLabel = "label_fieldDescribe";
	
	private final HorizontalPanel nameHP = new HorizontalPanel();
	private final VerticalPanel verticalPanel = new VerticalPanel();
	
	private final HorizontalPanel buttonsHorizontalPanel = new HorizontalPanel();
	
	private final Label nameLabel = new Label("name");
	
	private final TextBox name = new TextBox();
	private final Button addButton = new Button("add");
	private final Button closeButton = new Button("close"); 
	
	public AcademicTitleForm() {
		setup();
	}
	
	private void setup() {
		setText("Academic title form");
		
		name.setText("academic title name");
		
		closeButton.addClickListener(new ClickListener(){
			public void onClick(Widget sender) {
				//Window.alert("nameHP " + nameHP);
				hide();
			}
		});

		addButton.addClickListener(new ClickListener(){
			public void onClick(Widget sender) {
				Window.alert("szerokosc  " + getOffsetWidth());
			}
		});
		

		addButton.addStyleName(styleButton);
		closeButton.addStyleName(styleButton);
		
		addButton.setWidth("100px");
		closeButton.setWidth("100px");
		
		
		nameLabel.addStyleName(styleDescribeLabel);
		nameHP.add(nameLabel);
		nameHP.add(name);
//		nameHP.setHeight("50px");
		nameHP.setCellVerticalAlignment(nameLabel, HasVerticalAlignment.ALIGN_MIDDLE); 
//		nameHP.setCellHeight(nameLabel, "50px");
		
		
		buttonsHorizontalPanel.add(addButton);
		buttonsHorizontalPanel.add(closeButton);

//		verticalPanel.setWidth("300px");
		verticalPanel.add(nameHP);
		verticalPanel.add(buttonsHorizontalPanel);

		DOM.addEventPreview(this);
		
		addPopupListener(new PopupListener(){
			public void onPopupClosed(PopupPanel sender, boolean autoClosed) {
				DOM.removeEventPreview(AcademicTitleForm.this);
			}
		});
		
		setWidget(verticalPanel);
		
	}

	

	public boolean onEventPreview(Event event) {
		if (DOM.eventGetType(event) == Event.ONKEYUP) {
			//if Esc pressed
			if (DOM.eventGetKeyCode(event) == 27) {
				hide();
			}
		}
		return super.onEventPreview(event);
	}
	
}
